<template>
  <VDialog
    @close="handleClose"
    @save="save"
    :loading="loading"
    width="480"
    title="批量推送专属链接"
  >
    <template #content>
      <div class="h-[120px] flex justify-center items-center">
        <div>
          <div>
            已选中:
            <div class="ml-[2px] mr-[6px] text-[#da0014]">{{
              ids?.length || 0
            }}</div
            >条
          </div>
          <div class="mt-[16px]">
            说明:确认后,系统自动通过飞书消息将专属链接推送给对应人员
          </div>
        </div>
      </div>
    </template>
  </VDialog>
</template>

<script setup>
import { ElMessage } from "element-plus";
import api from "../../api/index";
const props = defineProps({
  ids: { type: Array, default: () => [] },
});
const { ids } = toRefs(props);
const emit = defineEmits(["update:modelValue", "close", "refresh"]);
const loading = ref(false);
const handleClose = async (refresh) => {
  emit("update:modelValue", false);
  emit("close");
  if (refresh) emit("refresh");
};
const save = async () => {
  try {
    loading.value = true;
    let { code, message } = await api.sendLink({ user_ids: ids.value });
    if (code !== 200) return ElMessage.warning(message);
    ElMessage.success("推送成功");
    handleClose(true);
  } catch (error) {
  } finally {
    loading.value = false;
  }
};
</script>
